package com.sxz.sbs.module.search;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.sxz.sbs.R;
import com.sxz.sbs.applibrary.component.ClearEditText;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.base.BasePresenter;
import com.sxz.sbs.constant.IntentConstant;
import com.sxz.sbs.module.order.OrderSearchActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 搜索停车场界面
 *
 * @author tian
 * @date 2018.3.26
 * dec: 有时间 把搜索楼盘都用此界面   （现在此类页面过多）
 */
public class SearchParkingActivity extends BaseActivity {


    @BindView(R.id.cet_search_parking)
    ClearEditText cetSearchParking;
    private String keyWord = "";
    private boolean isFromOrder;
    public static final String IS_FROM_ORDER = "is_from_order";
    @Override
    protected void init() {
        keyWord = getIntent().getStringExtra(IntentConstant.SELECT_PARKING_KEY_WORD);
        isFromOrder = getIntent().getBooleanExtra(IS_FROM_ORDER,false);
        if (keyWord == null) {
            keyWord = "";
        }
        cetSearchParking.setText(keyWord);
        cetSearchParking.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    InputMethodManager imm = (InputMethodManager) v.getContext()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (imm.isActive()) {
                        imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
                    }

                    if (isFromOrder) {
                        startActivity(new Intent(SearchParkingActivity.this, OrderSearchActivity.class)
                        .putExtra(OrderSearchActivity.SEARCH_ORDER_KEY,cetSearchParking.getInputValue()));
                    } else {
                        Intent intent = new Intent();
                        intent.putExtra(IntentConstant.SELECT_PARKING_KEY_WORD,cetSearchParking.getInputValue());
                        setResult(1533,intent);
                        finish();
                    }

                    return true;
                }
                return false;
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_search_park;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }


    @OnClick(R.id.tv_search_tel_cancel)
    public void onViewClicked() {
        finish();
    }
}
